<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号">
              <j-input placeholder="请输入项目编号" v-model="queryParam.projectCode"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目状态">
                <j-dict-select-tag
                  placeholder="请选择项目状态"
                  v-model="queryParam.status"
                  dictCode="sys_common_status"
                />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> 
    </div> -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template v-if="record.status == 1">
            <!-- <a-popconfirm title="确定通过吗?" @confirm="() => handleAudit(record, 2)">
              <a>通过</a>
            </a-popconfirm>
            <a-divider type="vertical" />
            <a-popconfirm title="确定驳回吗?" @confirm="() => handleAudit(record, 3)">
              <a>驳回</a>
            </a-popconfirm> -->
            <a @click="goAudit(record.id)">审批</a>
            <a-divider type="vertical" />
          </template>
          <a @click="handleDetail(record)">详情</a>
        </span>
      </a-table>
    </div>

    <ex-project-modal ref="modalForm" @ok="modalFormOk" />
    <ex-project-cg-modal ref="modalCgForm" @ok="modalFormOk" />
    <audit-modal ref="auditModal" @ok="doAudit"></audit-modal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ExProjectModal from './modules/ExProjectModal'
import ExProjectCgModal from './modules/ExProjectCgModal'
import AuditModal from '@/views/exOperationRecord/AuditModal'
import '@/assets/less/TableExpand.less'
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'ExProjectList',
  mixins: [JeecgListMixin],
  components: {
    ExProjectModal,
    ExProjectCgModal,
    AuditModal,
  },
  data() {
    return {
      description: '立项项目管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'projectCode',
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
        },
        {
          title: '项目所在行政区域',
          align: 'center',
          dataIndex: 'regionCode_dictText',
        },
        {
          title: '投资项目统一代码',
          align: 'center',
          dataIndex: 'investProjectCode',
        },
        {
          title: '项目地址',
          align: 'center',
          dataIndex: 'address',
        },
        {
          title: '项目法人',
          align: 'center',
          dataIndex: 'legalPerson',
        },
        {
          title: '项目行业分类',
          align: 'center',
          dataIndex: 'industryType',
        },
        // {
        //   title: '资金来源',
        //   align: 'center',
        //   dataIndex: 'fundSource',
        // },
        // {
        //   title: '出资比例',
        //   align: 'center',
        //   dataIndex: 'contributionScale',
        // },
        // {
        //   title: '项目规模',
        //   align: 'center',
        //   dataIndex: 'projectScale',
        // },
       {
          title: '项目类型',
          align: 'center',
          dataIndex: 'bizType',
          customRender: function (t, r, index) {
            if (t == 'CG') {
              return '采购'
            }
            if (t == 'GC') {
              return '工程'
            }
            return ''
          },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status_dictText',
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          sorter: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exProject/exProject/auditList',
        delete: '/exProject/exProject/delete',
        deleteBatch: '/exProject/exProject/deleteBatch',
        exportXlsUrl: '/exProject/exProject/exportXls',
        importExcelUrl: 'exProject/exProject/importExcel',
        audit: 'exProject/exProject/audit',
      },
      dictOptions: {},
      superFieldList: [],
      queryParam: {
        status: '1',
      },
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'projectId', text: '项目标识码 (guid)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectCode', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'regionCode', text: '项目所在行政区域代码', dictCode: 'sys_kf_area' })
      fieldList.push({ type: 'string', value: 'investProjectCode', text: '投资项目统一代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'address', text: '项目地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'legalPerson', text: '项目法人', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'industriesType',
        text: '项目行业分类',
        dictCode: 'sys_industry_category',
      })
      fieldList.push({ type: 'string', value: 'fundSource', text: '资金来源', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contributionScale', text: '出资比例', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectScale', text: '项目规模', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contactor', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contactInformation', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'islixiang', text: '是否立项', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'notlixiang', text: '不立项原因', dictCode: '' })
      fieldList.push({ type: 'string', value: 'superviseDeptName', text: '监督部门名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'superviseDeptCode', text: '监督部门代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'approvalName', text: '项目审批文件名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'approvalNumber', text: '项目审批文号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'approvalAuthority', text: '项目审批单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'attachmentCode', text: '附件关联标识号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'platformCode', text: '交易系统标识码', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'stateOwnedFund', text: '国有资金（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'stateOwnedFundRatio', text: '国有资金比例', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'privateFund', text: '私有资金（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'privateFundRatio', text: '私有资金比例', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignFund', text: '外国政府及组织投资（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignFundRatio', text: '外国政府及组织投资比例', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignPrivateFund', text: '境外私人投资（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignPrivateFundRatio', text: '境外私人投资比例', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '项目状态', dictCode: 'sys_common_status' })
      fieldList.push({ type: 'int', value: 'version', text: '版本号', dictCode: '' })
      this.superFieldList = fieldList
    },
    goAudit(id) {
      var that = this
      that.$refs.auditModal.show(id)
    },
    doAudit(param) {
      var that = this
      that.confirmLoading = true
      httpAction(
        this.url.audit,
        { id: param.entryId, status: param.operateResult, operateOpinion: param.operateOpinion },
        'post'
      )
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.loadData()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    searchReset() {
      this.queryParam = { status: '1' }
      this.loadData()
    },
        handleDetail: function (record) {
      if (record.bizType == 'GC') {
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '详情'
        this.$refs.modalForm.disableSubmit = true
      }
      if (record.bizType == 'CG') {
        this.$refs.modalCgForm.edit(record)
        this.$refs.modalCgForm.title = '详情'
        this.$refs.modalCgForm.disableSubmit = true
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>